package com.web.dao;

import com.web.entity.RoleMenuExample;
import com.web.entity.RoleMenuKey;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface RoleMenuMapper {
    @SelectProvider(type = RoleMenuSqlProvider.class, method = "countByExample")
    int countByExample(RoleMenuExample example);

    @DeleteProvider(type = RoleMenuSqlProvider.class, method = "deleteByExample")
    int deleteByExample(RoleMenuExample example);

    @Delete({
            "delete from t_role_menu",
            " where role_id = #{roleId,jdbcType=BIGINT}",
            " and menu_id = #{menuId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(RoleMenuKey key);

    @Insert({
            "insert into t_role_menu (role_id, menu_id)",
            " values (#{roleId,jdbcType=BIGINT}, #{menuId,jdbcType=BIGINT})"
    })
    int insert(RoleMenuKey record);

    @InsertProvider(type = RoleMenuSqlProvider.class, method = "insertSelective")
    int insertSelective(RoleMenuKey record);

    @SelectProvider(type = RoleMenuSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "role_id", property = "roleId", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "menu_id", property = "menuId", jdbcType = JdbcType.BIGINT, id = true)
    })
    List<RoleMenuKey> selectByExample(RoleMenuExample example);

    @UpdateProvider(type = RoleMenuSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") RoleMenuKey record, @Param("example") RoleMenuExample example);

    @UpdateProvider(type = RoleMenuSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") RoleMenuKey record, @Param("example") RoleMenuExample example);

    @Insert({"<script>",
            "insert into t_role_menu (role_id, menu_id) values ",
            " <foreach collection='list' item='item' index='index' separator=','>(#{item.roleId,jdbcType=BIGINT}, #{item.menuId,jdbcType=BIGINT})</foreach>",
            "</script>"})
    int batchInsert(List<RoleMenuKey> list);
}